home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / misc / unix / tracker_4_3.lzh / tracker / extern.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-13  |  15.1 KB  |  541 lines

  1. /* extern.h 
  2.     vi:se ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: extern.h,v 4.1 1994/02/04 14:54:08 espie Exp espie $
  6.  * $Log: extern.h,v $
  7.  * Revision 4.1  1994/02/04  14:54:08  espie
  8.  * Fixed up ansi C stupid bug.
  9.  *
  10.  * Revision 4.0  1994/01/11  17:46:25  espie
  11.  * Lots of new proto for all functions.
  12.  *
  13.  * Revision 1.10  1994/01/09  17:36:22  Espie
  14.  * Generalized open.c.
  15.  *
  16.  * Revision 1.9  1994/01/09  04:50:56  Espie
  17.  * Comments.
  18.  *
  19.  * Revision 1.8  1994/01/08  19:43:57  Espie
  20.  * Added checkbrk.
  21.  *
  22.  * Revision 1.7  1994/01/08  03:55:43  Espie
  23.  * General cleanup.
  24.  *
  25.  * Revision 1.6  1994/01/06  22:32:42  Espie
  26.  * Suppressed some unused code.
  27.  *
  28.  * Revision 1.5  1994/01/05  13:53:25  Espie
  29.  * Better portability.
  30.  *
  31.  * Revision 1.4  1993/12/28  13:54:44  Espie
  32.  * Removed init_display.
  33.  * No more reentrency problems with INIT_ONCE.
  34.  * Protos for ui: notice, info, scroller, pattern display.
  35.  *
  36.  * Revision 1.3  1993/12/26  22:48:18  Espie
  37.  * Mostly working.
  38.  * Just dies with a guru.
  39.  * Plus timing problems at start.
  40.  *
  41.  * Revision 1.2  1993/12/26  18:54:21  Espie
  42.  * New prototypes.
  43.  *
  44.  * Revision 1.1  1993/12/26  00:55:53  Espie
  45.  * Initial revision
  46.  *
  47.  * Revision 3.15  1993/12/04  16:12:50  espie
  48.  * Added prototypes.
  49.  *
  50.  * Revision 3.14  1993/12/02  15:45:33  espie
  51.  * Added some protos.
  52.  *
  53.  * Revision 3.13  1993/11/17  15:31:16  espie
  54.  * *** empty log message ***
  55.  *
  56.  * Revision 3.12  1993/11/11  20:00:03  espie
  57.  * Amiga support.
  58.  *
  59.  * Revision 3.10  1993/07/18  10:39:44  espie
  60.  * Added pid, fork, show.
  61.  *
  62.  * Revision 3.8  1993/01/15  14:00:28  espie
  63.  * Added bg/fg test.
  64.  *
  65.  * Revision 3.7  1992/12/03  15:00:50  espie
  66.  * stty_sane.
  67.  *
  68.  * Revision 3.5  1992/11/24  10:51:19  espie
  69.  * New audio functions.
  70.  *
  71.  * Revision 3.2  1992/11/22  17:20:01  espie
  72.  * Simplified delay_pattern.
  73.  *
  74.  * Revision 3.1  1992/11/19  20:44:47  espie
  75.  * Protracker commands.
  76.  *
  77.  * Revision 3.0  1992/11/18  16:08:05  espie
  78.  * New release.
  79.  *
  80.  * Revision 2.19  1992/11/17  17:06:25  espie
  81.  * Lots of new functions to account for new interface.
  82.  * open_file support.
  83.  * Separated mix/stereo stuff.
  84.  * Added possibility to get back to MONO for the sgi.
  85.  * Added stereo capabilities to the indigo version.
  86.  * Added some new song types to automatize the choice process.
  87.  * Moved resampling to audio, added prototype.
  88.  * Added SAMPLE_FAULT, for trying to play
  89.  * a note without a sample (not really an error).
  90.  *
  91.  * Revision 1.7  1991/11/08  14:25:55  espie
  92.  * Modified audio prototype so that you can change
  93.  * frequency.
  94.  * Added prototype for release_song.
  95.  * Added arpeggio effect.
  96.  * Added entries for new effects.
  97.  * Added entries for commands.c.
  98.  */
  99.  
  100.  
  101.  
  102. /* audio.c */
  103. #define ACCURACY 12
  104. #define fix_to_int(x) ((x) >> ACCURACY)
  105. #define int_to_fix(x) ((x) << ACCURACY)
  106.  
  107.  
  108. /* release_audio_channels:
  109.  * free every audio channel previously allocated
  110.  */
  111. XT void release_audio_channels P((void));
  112.  
  113. /* chan = new_channel_tag_list(prop):
  114.  * allocates a new channel for the current song
  115.  * No properties are currently defined.
  116.  */
  117. XT struct audio_channel *new_channel_tag_list P((struct tag *prop));
  118.  
  119. /* init_tables(oversample, frequency):
  120.  * precomputes the step_table and the pitch_table
  121.  * according to the desired oversample and frequency.
  122.  * This is static, you can call it again whenever you want.
  123.  * Adjust the currently used audio channels if needed.
  124.  */
  125. XT void init_tables P((int oversample, int frequency));
  126.  
  127. /* resample(oversample, number):
  128.  * send number samples out computed according
  129.  * to the current state of channels
  130.  * and oversample.
  131.  */
  132. XT void resample P((int oversample, int number));
  133.  
  134. /* play_note(au, samp, pitch)
  135.  * set audio channel au to play samp at pitch
  136.  */
  137. XT void play_note P((struct audio_channel *au, struct sample_info *samp, \
  138. int pitch));
  139.  
  140. /* set_play_pitch(au, pitch):
  141.  * set channel au to play at pitch pitch
  142.  */
  143. XT void set_play_pitch P((struct audio_channel *au, int pitch));
  144.  
  145. /* set_play_volume(au, volume):
  146.  * set channel au to play at volume volume
  147.  */
  148. XT void set_play_volume P((struct audio_channel *au, int volume));
  149.  
  150. /* set_play_position(au, pos):
  151.  * set position in sample for channel au at given offset
  152.  */
  153. XT void set_play_position P((struct audio_channel *au, int pos));
  154.  
  155.  
  156. /* automaton.c */
  157. /* init_automaton(a, song, start):
  158.  * put the automaton a in the right state to play song from pattern start.
  159.  */
  160. XT void init_automaton P((struct automaton *a, struct song *song, int start));
  161.  
  162. /* next_tick(a):
  163.  * set up everything for the next tick.
  164.  */
  165. XT void next_tick P((struct automaton *a));
  166.  
  167.  
  168. /* commands.c */
  169. /* init_effects(): sets up all data for the effects */
  170. /* (not set up as auto_init due to huge overhead) */
  171. XT void init_effects P((void (*table[])()));
  172.  
  173. /* do_nothing: this is the default behavior for an effect.
  174.  */
  175. XT void do_nothing P((struct channel *ch));
  176.  
  177.  
  178. /* dump_song.c */
  179. /* dump_song(s): 
  180.  * displays some information pertinent to the given 
  181.  * song s.
  182.  */
  183. XT void dump_song P((struct song *song));
  184.  
  185.  
  186. /* display.c */
  187.  
  188. /* dump_event(ch, e): dump event e as occuring on channel ch
  189.  */
  190. XT void dump_event P((struct channel *ch, struct event *e));
  191.  
  192.  
  193. /* main.c */
  194.  
  195. #define OLD 0
  196. #define NEW 1
  197. /* special new type: for when we try to read it as both types.
  198.  */
  199. #define BOTH 2
  200. /* special type: does not check the signature */
  201. #define NEW_NO_CHECK 3
  202.  
  203.  
  204. /* error types. Everything is centralized,
  205.  * and we check in some places (see st_read, player and main)
  206.  * that there was no error. Additionnally signal traps work
  207.  * that way too.
  208.  */
  209.  
  210. /* normal state */
  211. #define NONE 0  
  212. /* read error */
  213. #define FILE_TOO_SHORT 1
  214. #define CORRUPT_FILE 2
  215. /* trap error: goto next song right now */
  216. #define NEXT_SONG 3
  217. /* run time problem */
  218. #define FAULT 4
  219. /* the song has ended */
  220. #define ENDED 5
  221. /* unrecoverable problem: typically, trying to 
  222.  * jump to nowhere land.
  223.  */
  224. #define UNRECOVERABLE 6
  225. /* Missing sample. Very common error, not too serious. */
  226. #define SAMPLE_FAULT 7
  227. /* New */
  228. #define PREVIOUS_SONG 8
  229. #define OUT_OF_MEM 9
  230. XT int error;
  231.  
  232. /* notes.c */
  233. #define NUMBER_NOTES 120
  234. #define NUMBER_FINETUNES 17
  235. XT short pitch_table[NUMBER_NOTES][NUMBER_FINETUNES];    /* 120 * 17 = big ! */
  236.  
  237. /* note = find_note(pitch):
  238.  * find note corresponding to a given pitch. 
  239.  */
  240. XT int find_note P((int pitch));
  241.  
  242. /* oldtranspose = transpose_song(song, newtranspose):
  243.  * tranpose song to a new pitch
  244.  */
  245. XT int transpose_song P((struct song *song, int newtranspose));
  246.  
  247. /* name = name_of_note(note):
  248.  * name of the note. Warning! This name is only valid
  249.  * until a new call to name_of_note.
  250.  */
  251. XT char *name_of_note P((int note));
  252.  
  253.  
  254.  
  255.  
  256.  
  257. /* open.c */
  258. /* handle = open_file(filename, mode, path):
  259.  * transparently open a compressed file.
  260.  */
  261. XT struct exfile *open_file P((char *fname, char *fmode, char *path));
  262.  
  263. /* handle = file_handle(f):
  264.  * obtain the actual FILE handle from the private structure
  265.  */
  266. XT FILE *file_handle P((struct exfile *f));
  267.  
  268. /* close_file(handle):
  269.  * close a file that was opened with open_file.
  270.  */
  271. XT void close_file P((struct exfile *file));
  272.  
  273. XT int getc_file P((struct exfile *file));
  274. XT int tell_file P((struct exfile *file));
  275.  
  276.  
  277.  
  278.  
  279. /* player.c */
  280.  
  281. /* reset_note(ch, note, pitch):
  282.  * set channel ch to play note at pitch pitch
  283.  */
  284. XT void reset_note P((struct channel *ch, int note, int pitch));
  285.  
  286. /* set_current_pitch(ch, pitch):
  287.  * set ch to play at pitch pitch
  288.  */
  289. XT void set_current_pitch P((struct channel *ch, int pitch));
  290.  
  291. /* set_current_volume(ch, volume):
  292.  * set channel ch to play at volume volume
  293.  */
  294. XT void set_current_volume P((struct channel *ch, int volume));
  295.  
  296. /* set_position(ch, pos):
  297.  * set position in sample for current channel at given offset
  298.  */
  299. XT void set_position P((struct channel *ch, int pos));
  300.  
  301. /* init_player(oversample, frequency):
  302.  * sets up the player for a given oversample and
  303.  * output frequency.
  304.  * Note: we can call init_player again to change oversample and
  305.  * frequency.
  306.  */
  307. XT void init_player P((int o, int f));
  308.  
  309. /* play_song(song, start):
  310.  * play the song.
  311.  */
  312. XT struct tag *play_song P((struct song *song, int start));
  313. /* returns tags as shown further down in get_ui */
  314.  
  315.  
  316.  
  317. /* st_read.c */
  318. /* s = read_song(f, type):
  319.  * tries to read f as a song of type NEW/OLD.
  320.  * returns NULL (and an error) if it doesn't work.
  321.  * Returns a dynamic song structure if successful.
  322.  */
  323. XT struct song *read_song P((struct exfile *f, int type));
  324.  
  325. /* release_song(s):
  326.  * release all the memory song occupies.
  327.  */
  328. XT void release_song P((struct song *song));
  329.  
  330.  
  331.  
  332. /* setup_audio.c */
  333. /* setup_audio(ask_freq, stereo, oversample):
  334.  * setup the audio output with these values 
  335.  */
  336. XT void setup_audio P((int f, boolean s, int o));
  337. /* do_close_audio():
  338.  * close audio only if needed
  339.  */
  340. XT void do_close_audio P((void));
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348. /* xxx_audio.c */
  349. /* frequency = open_audio(f, s):
  350.  * try to open audio with a sampling rate of f, and eventually stereo.
  351.  * We get the real frequency back. If we ask for 0, we
  352.  * get the ``preferred'' frequency.
  353.  * Note: we have to close_audio() before we can open_audio() again.
  354.  * Note: even if we don't ask for stereo, we still have to give a
  355.  * right and left sample.
  356.  */
  357. XT int open_audio P((int f, int s));
  358. /* close_audio():
  359.  * returns the audio to the system control, doing necessary
  360.  * cleanup
  361.  */
  362. XT void close_audio P((void));
  363. /* set_mix(percent): set mix channels level.
  364.  * 0: spatial stereo. 100: mono.
  365.  */
  366. XT void set_mix P((int percent));
  367.  
  368. /* output_samples(l, r): outputs a pair of stereo samples.
  369.  * Samples are 15 bits signed.
  370.  */
  371. XT void output_samples P((int left, int right));
  372.  
  373. /* flush_buffer(): call from time to time, because buffering
  374.  * is done by the program to get better (?) performance.
  375.  */
  376. XT void flush_buffer P((void));
  377.  
  378. /* discard_buffer(): try to get rid of the buffer contents
  379.  */
  380. XT void discard_buffer P((void));
  381.  
  382. /* new_freq = update_frequency():
  383.  * if !0, frequency changed and playing should be updated accordingly
  384.  */
  385. XT int update_frequency P((void));
  386.  
  387. /* set_synchro(boolean):
  388.  * try to synchronize audio output by using a smaller buffer
  389.  */
  390. XT void set_synchro P((boolean s));
  391.  
  392. #ifdef SPECIAL_SAMPLE_MEMORY
  393. XT GENERIC alloc_sample P((int len));
  394. XT void free_sample P((GENERIC s));
  395. XT int obtain_sample P((GENERIC start, int l, FILE *f));
  396.  
  397. #else
  398. #define alloc_sample(len)        calloc(len, 1)
  399. #define free_sample(sample)        free(sample)
  400. #define obtain_sample(start, l, f)    fread(start, 1, l, f)
  401. #endif
  402.  
  403.  
  404.  
  405. /* tools.c */
  406. /* v = read_env(name, default):
  407.  * read a scalar value in the environment
  408.  */
  409. XT int read_env P((char *name, int def));
  410.  
  411.  
  412.  
  413.  
  414. /* autoinit.c */
  415. /* used for decentralizing initialization/termination of various
  416.  * system routines
  417.  */
  418.  
  419. /* end_all(s): the program must exit now, after displaying s to the user, usually 
  420.  * through notice and calling all stacked at_end() functions. s may be 0 for normal
  421.  * exit. DO NOT use exit() anywhere in tracker but end_all() instead.
  422.  */
  423. XT void end_all P((char *s));
  424.  
  425. /* at_end(cleanup): stack cleanup to be called at program's termination
  426.  */
  427. XT void at_end P((void (*cleanup)(void)));
  428.  
  429. /* INIT_ONCE: macro for autoinitialization of routines.
  430.  * modules that need an init routine should LOCAL void INIT = init_routine,
  431.  * and add INIT_ONCE; at EVERY possible first entry point for their routine.
  432.  * (I mean every, don't try to second-guess me !)
  433.  */
  434. #define INIT_ONCE        if (INIT)    {void (*func)P((void)) = INIT; INIT = 0; (*func)();}
  435.  
  436.  
  437. /* $(UI)/ui.c */
  438. /* see unix/ui.c for the general unix implementation.
  439.  * The old may_getchar() has been replaced by the tag-based
  440.  * get_ui
  441.  */
  442. /* get_ui(): returns an array of tags that reflect the current user-interface
  443.  * actions. Unknown tags WILL be ignored.
  444.  * Note that get_ui will be called about once every tick, providing a poor man's
  445.  * timer to the interface writer if needed to code multiple actions on the same
  446.  * user-input. See unix/termio.c for a good example.
  447.  * see amiga/ui.c for the correct way to do it when you have a real timer.
  448.  *
  449.  * VERY IMPORTANT: who do the tags belong to ?
  450.  *    as a general rule, result (and their values) MUST only be considered
  451.  *    valid between two calls to get_ui ! Be careful to call get_ui ONLY at
  452.  *    reasonable places.
  453.  *    One exception: structures that are dynamically allocated (like UI_LOAD_SONG
  454.  *    values) will ONLY get freed when you ask for it !
  455.  */
  456. XT struct tag *get_ui P((void));
  457. #define BASE_UI 10
  458. #define UI_NEXT_SONG    (BASE_UI)            /* load next song */
  459. #define UI_PREVIOUS_SONG (BASE_UI + 1)    /* load previous song */
  460. #define UI_LOAD_SONG (BASE_UI + 2)        /* load song. Name as value */
  461. #define UI_SET_BPM (BASE_UI + 3)          /* set beat per minute to value */
  462. #define UI_JUMP_TO_PATTERN (BASE_UI + 4)  /* jump to pattern #value. Use display_pattern to
  463.                                            * keep in sync with the player
  464.                                            */
  465. #define UI_RESTART (BASE_UI + 5)          /* restart current song. Not quite jump to 0 */
  466. #define UI_QUIT (BASE_UI + 6)             /* need I say more ? */
  467. #define UI_DISPLAY (BASE_UI + 7)          /* status of scrolling window: true or false */
  468.  
  469.  
  470. /* player.c translates the get_ui() tags in a standard way.
  471.  * Actually it doesn't translate anything right now...
  472.  */
  473. #define BASE_PLAY 20
  474. #define PLAY_NEXT_SONG UI_NEXT_SONG
  475. #define PLAY_PREVIOUS_SONG UI_PREVIOUS_SONG
  476. #define PLAY_LOAD_SONG UI_LOAD_SONG
  477.  
  478. #define PLAY_ERROR BASE_PLAY
  479.  
  480. /* Most of these functions are information display function.
  481.  * A correct implementation should heed run_in_fg() if needed
  482.  */
  483.  
  484. /* notice(s): important message for the user (terminal error maybe).
  485.  * take extra pain to make it apparent even if run in background
  486.  */
  487. XT void notice P((char *s));
  488.  
  489. /* status(s): some indication of the system current status... 
  490.  * Used for fleeing error messages too. 
  491.  * s = 0 is valid and indicates return to the default status.
  492.  */
  493. XT void status P((char *s));
  494.  
  495. /* begin_info: open a logical information window.
  496.  * returns 0 if the window couldn't be opened.
  497.  * A NULL window shouldn't be used, but don't count on it !
  498.  */
  499. XT GENERIC begin_info P((char *title));
  500. /* info(handle, line): add a line to the info window,
  501.  * completing the current line if applicable
  502.  */
  503. XT void info P((GENERIC handle, char *line));
  504. /* infos(handle, line): add to the current line of the info window
  505.  */
  506. XT void infos P((GENERIC handle, char *s));
  507. /* end_info(handle): this window is complete...
  508.  */
  509. XT void end_info P((GENERIC handle));
  510.  
  511. /* Scrolling score display:
  512.  * new_scroll() returns a writable buffer of 4*14-1 characters in
  513.  * which the program (usually display.c) will write what it wills.
  514.  * It can return 0 if not applicable.
  515.  */
  516. XT char *new_scroll P((void));
  517.  
  518. /* scroll: returns this scrolling line to the program. Note that
  519.  * scroll doesn't take any argument, and implies calls to new_scroll/scroll
  520.  * are paired. After a call to scroll, the last pointer returned by new_scroll
  521.  * should be considered invalid !
  522.  */
  523. XT void scroll P((void));
  524.  
  525. /* display_pattern(current, total): we are at current/total in the current song
  526.  * may be used as a poor man's timer.
  527.  */
  528. XT void display_pattern P((int current, int total));
  529.  
  530. /* song_title(s): the current song title is s.
  531.  * ui implementors: Don't count on this pointer remaining valid AFTER the call,
  532.  * make a copy if needed
  533.  */
  534. XT void song_title P((char *s));
  535.  
  536. /* boolean checkbrk():
  537.  * check whether a break occured and we should end right now.
  538.  * Call it often enough (like when loading songs and stuff)
  539.  */
  540. XT boolean checkbrk P((void));
  541.